// poke_dlg_key_control.cpp : implementation file
//

#include "stdafx.h"
#include "poke.h"
#include "ui/poke_dlg_key_control.h"
#include "poke_framework.h"
#include "models/atom_interface/ai_window_poker.h"

// CPokeDlgKeyControl dialog

IMPLEMENT_DYNAMIC(CPokeDlgKeyControl, CDialog)

CPokeDlgKeyControl::CPokeDlgKeyControl(CWnd* pParent /*=NULL*/)
	: CDialog(CPokeDlgKeyControl::IDD, pParent)
    , m_strKeyInput(_T(""))
{
    PokeFramework::get()->AddMCA(this);
}

CPokeDlgKeyControl::~CPokeDlgKeyControl()
{
}

void CPokeDlgKeyControl::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);

    DDX_Text(pDX, IDC_EDIT_KEY_INPUT_STRING, m_strKeyInput);
}

BEGIN_MESSAGE_MAP(CPokeDlgKeyControl, CDialog)
    ON_BN_CLICKED(IDC_BUTTON_WM_KEYDOWN, &CPokeDlgKeyControl::OnBnClickedButtonWmKeydown)
    ON_BN_CLICKED(IDC_BUTTON_WM_KEYUP, &CPokeDlgKeyControl::OnBnClickedButtonWmKeyup)
    ON_BN_CLICKED(IDC_BUTTON_WM_KEY_INPUT, &CPokeDlgKeyControl::OnBnClickedButtonWmKeyInput)
END_MESSAGE_MAP()

BOOL CPokeDlgKeyControl::PostKeyMsg(DWORD *pMsgList, int nMsgCount)
{
    PPSendMultiKeyMessage oRequest;
    int i, j, nLength = m_strKeyInput.GetLength();
    for(i = 0; i < nLength; ++i) {
        for(j = 0; j < nMsgCount; ++j) {
            oRequest.m_vMsgList.push_back(PPSendKeyMessage(pMsgList[j], m_strKeyInput[i]));
        }
    }

    return Execute(PAN_WINDOW_POKER, PFI_SEND_MULTI_KEY_MESSAGE, &oRequest, NULL);
}

void CPokeDlgKeyControl::OnBnClickedButtonWmKeydown()
{
    // TODO: Add your control notification handler code here
    UpdateData(TRUE);

    DWORD msg = WM_KEYDOWN;
    PostKeyMsg(&msg, 1);
}

void CPokeDlgKeyControl::OnBnClickedButtonWmKeyup()
{
    // TODO: Add your control notification handler code here
    UpdateData(TRUE);

    DWORD msg = WM_KEYUP;
    PostKeyMsg(&msg, 1);
}

void CPokeDlgKeyControl::OnBnClickedButtonWmKeyInput()
{
    // TODO: Add your control notification handler code here
    UpdateData(TRUE);

    DWORD msg[] = { WM_KEYDOWN, WM_KEYUP };
    PostKeyMsg(msg, 2);
}

// CPokeDlgKeyControl message handlers
